﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Net;
using System.Threading;
using hcmsservice.BusinessLogicLayer;
using hcmsservice.Configuration;

namespace hcmsservice
{
    public partial class HcmsService : ServiceBase
    {
        private Thread MainThread;
        //private Thread MainThread1;

        public HcmsService()
        {
            InitializeComponent();

            MainThread = new Thread(new ThreadStart(ThreadFunc));
            MainThread.Priority = ThreadPriority.Normal;

            //MainThread1 = new Thread(new ThreadStart(ThreadFunc1));
            //MainThread1.Priority = ThreadPriority.Normal;
        }

        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。
            System.Threading.Thread.Sleep(8000);
            MainThread.Start();
            //MainThread1.Start();
        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            MainThread.Abort();
            //MainThread1.Abort();
        }

        #region 业务逻辑

        //计算会员等级
        public static void ThreadFunc()
        {
            while (true) {
                int startTime = int.Parse(System.Configuration.ConfigurationManager.AppSettings["WindoServiceStartTime"]);
                if (DateTime.Now.Hour.Equals(startTime)) {
                    ProcessUserLevel userlevel = new ProcessUserLevel();
                    userlevel.StartUserUpLevel();
                    //暂停1小时
                    System.Threading.Thread.Sleep(3600000);
                }
                //暂停1分钟
                System.Threading.Thread.Sleep(60000);
            }
        }


        public static void ThreadFunc1()
        {
            while (true)
            {
                int startTime = int.Parse(System.Configuration.ConfigurationManager.AppSettings["WindoServiceStartTime"]);
                if (DateTime.Now.Hour.Equals(startTime)){
                    scoreStat sstat = new scoreStat();
                    sstat.start();
                    //暂停1小时
                    System.Threading.Thread.Sleep(3600000);
                }

                //判断订单绑定礼品时，订单提交是否成功，如果成功则更新礼品日志的订单状态，否则删掉礼品日志
                presentfogstatus pfog = new presentfogstatus();
                pfog.start();

                //暂停5分钟
                
                System.Threading.Thread.Sleep(300000);
            }
        }

        

        #endregion
    }
   
}
